package mutsumimod.monitors;

import basemod.interfaces.OnCardUseSubscriber;
import basemod.interfaces.OnStartBattleSubscriber;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import mutsumimod.cards.deprecated.PathDependency;
import mutsumimod.patches.CopyPatch;

import java.util.ArrayList;

public class PathDependencyMonitor extends BaseMonitor implements OnCardUseSubscriber, OnStartBattleSubscriber {

    public static ArrayList<AbstractCard> cardsUsedCombat = new ArrayList<>();

    @Override
    public void receiveCardUsed(AbstractCard abstractCard) {
        if(!CopyPatch.shouldCopyUse(abstractCard)){
            cardsUsedCombat.add(abstractCard);
        }

        CardGroup[] piles = {
                AbstractDungeon.player.hand,
                AbstractDungeon.player.drawPile,
                AbstractDungeon.player.discardPile
        };

        for (CardGroup pile : piles) {
            processPile(pile);
        }
    }

    public void processPile(CardGroup pile) {
        for(AbstractCard c:pile.group){
            if(c instanceof PathDependency){
                ((PathDependency) c).updateDescription();
            }
        }
    }

    @Override
    public void receiveOnBattleStart(AbstractRoom abstractRoom) {
        cardsUsedCombat.clear();
    }


}
